like = [
    [0,0,0,0,0,0],
    [0,0,0,1,1,0],
    [0,1,1,0,0,1],
    [0,0,1,1,0,0],
    [0,0,0,0,1,0],
    [0,0,1,0,0,1]
]

book = [0] * 6
stu = [0] * 6

count = 0

def output():
    global count, book
    count += 1
    print('answer:', count)
    for i in range(1, 6):
        print(i,":", chr(64 + book[i])) # A:65

def search(i):
    global stu, book
    for j in range(1,6):
        if not stu[j] and like[i][j]:
            stu[j] = 1
            book[i] = j # 第i个人选了第j本书
            if i == 5:
                output()
            else:
                search(i + 1)
            stu[j] = 0

def main():
    search(1)

main()

